from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login
from django.contrib.auth.views import LoginView
from django.urls import reverse_lazy

class HumanisticLoginView(LoginView):
    """人文风格登录视图"""
    template_name = 'admin/humanistic_login.html'
    redirect_authenticated_user = True
    
    def get_success_url(self):
        # 登录成功后重定向到管理后台
        return reverse_lazy('admin:index')
    
    def form_valid(self, form):
        # 验证表单并登录用户
        response = super().form_valid(form)
        return response
    
    def form_invalid(self, form):
        # 表单验证失败时的处理
        return super().form_invalid(form)